﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LinqToMyClass
{
    public class MyClass1
    {
        public int Prop1 { get; set; }
        public string Prop2 { get; set; }

        internal bool Visible { get; set; }

        public static List<MyClass1> GetMyClasses()
        {
            return new List<MyClass1> { 
                                            new MyClass1 { Prop1 = 1, Prop2 = "Teste 1", Visible = true } ,
                                            new MyClass1 { Prop1 = 2, Prop2 = "Wrap 2", Visible = false } ,  
                                            new MyClass1 { Prop1 = 10, Prop2 = "Teste 10", Visible = false } ,
                                            new MyClass1 { Prop1 = 20, Prop2 = "Wrap 20", Visible = true } 
                                        };
        }

    }












    public static class MyClassLinqQueries
    {
        public static IEnumerable<MyClass1> WhereVisible(this IEnumerable<MyClass1> listaClasses, Func<MyClass1, bool> delegateFunc, bool visible)
        {
            foreach (MyClass1 classe in listaClasses)
            {
                if (delegateFunc(classe) && visible == classe.Visible)
                    yield return classe;
            }
        }

        
        
        
        
        
        
        
        
        
        
        
        
        
        public static IEnumerable<MyClass1> GetVisible(this IEnumerable<MyClass1> listaClasses, bool visible)
        {
            foreach (MyClass1 classe in listaClasses)
            {
                if (visible == classe.Visible)
                    yield return classe;
            }
        }

    }
}
